package com.mx.tool.form.factory;

import com.intellij.ui.JBColor;
import com.mx.tool.form.window.other.CreateWindow;
import com.mx.tool.form.window.other.IpWindow;
import com.mx.tool.form.window.other.MobileWindow;
import com.mx.tool.form.window.other.WebSourceWindow;
import com.mx.tool.form.window.qr.QrCreateWindow;
import com.mx.tool.form.window.qr.QrJxWindow;

import javax.swing.*;

/**
 * @Author: 徐建鹏.
 * @create: 2021-11-10 08:51
 * @Description:
 */
public class OtherFactory {

    private final static IpWindow IP_WINDOW;
    private final static MobileWindow MOBILE_WINDOW;
    private final static CreateWindow CREATE_WINDOW;
    private final static WebSourceWindow WEB_SOURCE_WINDOW;

    static {
        IP_WINDOW = new IpWindow();
        MOBILE_WINDOW = new MobileWindow();
        CREATE_WINDOW = new CreateWindow();
        WEB_SOURCE_WINDOW = new WebSourceWindow();
    }


    /*
    添加监听
     */
    public static void addActionListeners(JButton ipButton, JButton mobileButton, JButton createButton,JButton webSourceButton,JPanel otherPanel) {
        JPanel ipJPanel = IP_WINDOW.getContent();
        JPanel mobileJPanel = MOBILE_WINDOW.getContent();
        JPanel createJPanel = CREATE_WINDOW.getContent();
        JPanel webSourceJPanel = WEB_SOURCE_WINDOW.getContent();
        otherPanel.add("ipJPanel", ipJPanel);
        otherPanel.add("mobileJPanel", mobileJPanel);
        otherPanel.add("createJPanel", createJPanel);
        otherPanel.add("webSourceJPanel", webSourceJPanel);
        ipButton.setForeground(JBColor.GREEN);
        ipButton(ipButton,mobileButton,createButton,webSourceButton,ipJPanel,mobileJPanel,createJPanel,webSourceJPanel);
        mobileButton(ipButton,mobileButton,createButton,webSourceButton,ipJPanel,mobileJPanel,createJPanel,webSourceJPanel);
        createButton(ipButton,mobileButton,createButton,webSourceButton,ipJPanel,mobileJPanel,createJPanel,webSourceJPanel);
        webSourceButton(ipButton,mobileButton,createButton,webSourceButton,ipJPanel,mobileJPanel,createJPanel,webSourceJPanel);
    }

    private static void ipButton(JButton ipButton, JButton mobileButton,JButton createButton,JButton webSourceButton,
                                 JPanel ipJPanel, JPanel mobileJPanel, JPanel createJPanel, JPanel webSourceJPanel) {
        ipButton.addActionListener(e -> {
            mobileJPanel.setVisible(false);
            mobileButton.setForeground(JBColor.BLACK);
            createJPanel.setVisible(false);
            createButton.setForeground(JBColor.BLACK);
            webSourceJPanel.setVisible(false);
            webSourceButton.setForeground(JBColor.BLACK);
            ipJPanel.setVisible(true);
            ipButton.setForeground(JBColor.GREEN);
        });
    }

    private static void mobileButton(JButton ipButton, JButton mobileButton,  JButton createButton,JButton webSourceButton,
                                     JPanel ipJPanel, JPanel mobileJPanel, JPanel createJPanel,JPanel webSourceJPanel) {
        mobileButton.addActionListener(e -> {
            webSourceJPanel.setVisible(false);
            webSourceButton.setForeground(JBColor.BLACK);
            createJPanel.setVisible(false);
            createButton.setForeground(JBColor.BLACK);
            ipJPanel.setVisible(false);
            ipButton.setForeground(JBColor.BLACK);
            mobileJPanel.setVisible(true);
            mobileButton.setForeground(JBColor.GREEN);

        });
    }

    private static void createButton(JButton ipButton, JButton mobileButton,JButton createButton,JButton webSourceButton,
                                     JPanel ipJPanel, JPanel mobileJPanel, JPanel createJPanel,JPanel webSourceJPanel) {
        createButton.addActionListener(e -> {
            webSourceJPanel.setVisible(false);
            webSourceButton.setForeground(JBColor.BLACK);
            ipJPanel.setVisible(false);
            ipButton.setForeground(JBColor.BLACK);
            mobileJPanel.setVisible(false);
            mobileButton.setForeground(JBColor.BLACK);
            createJPanel.setVisible(true);
            createButton.setForeground(JBColor.GREEN);

        });
    }

    private static void webSourceButton(JButton ipButton, JButton mobileButton,JButton createButton,JButton webSourceButton,
                                     JPanel ipJPanel, JPanel mobileJPanel, JPanel createJPanel,JPanel webSourceJPanel) {
        webSourceButton.addActionListener(e -> {

            ipJPanel.setVisible(false);
            ipButton.setForeground(JBColor.BLACK);
            mobileJPanel.setVisible(false);
            mobileButton.setForeground(JBColor.BLACK);
            createJPanel.setVisible(false);
            createButton.setForeground(JBColor.BLACK);
            webSourceJPanel.setVisible(true);
            webSourceButton.setForeground(JBColor.GREEN);

        });
    }

}
